<script type="text/javascript">
<!--{literal}
$(document).ready
(
    function()
    {
	$('div#time-management')
	    .dialog('option','title','Тайм-менеджмент')
	    .dialog('option','height',{/literal}{$smarty.session.manager.options.dialog.timeReport.height|default:'"auto"'}{literal})
	    .dialog('option','width',{/literal}{$smarty.session.manager.options.dialog.timeReport.width|default:'400'}{literal});

	$('a#time-management-button').click
	(
	    function()
	    {
		$('div#time-management')
		    .dialog('open');
	    }
	);

	$.getJSON
	(
	    'timeReport.php',
	    { do: 'init' },
	    function(options)
	    {
		$('table#jqg-TimeReport')
		    .jqGrid(options);

		$('table#jqg-TimeReport')
		    .setGridHeight({/literal}{$smarty.session.manager.options.dialog.timeReport.height}{literal}-170)
		    .setGridWidth({/literal}{$smarty.session.manager.options.dialog.timeReport.width|default:'400'}{literal}-30);

		$('div#time-management').dialog
		({
		    'resizeStop':	function(event,ui)
					{
					    $.getJSON
					    (
						'options.php',
						{
						    module:	'dialog',
						    moduleName:	'timeReport',
						    width:	ui.size.width,
						    height:	ui.size.height
						}
					    );
					    $('table#jqg-TimeReport').setGridHeight(ui.size.height-170);
					    $('table#jqg-TimeReport').setGridWidth(ui.size.width-30);
					}
		});

		$('select#manager-id').change
		(
		    function()
		    {
			$('table#jqg-TimeReport')
			    .jqGrid
			    (
				'setGridParam',
				{
				    url:	'timeReport.php?manager_id='+$(this).val()
						+'&startDate='+$('#tm-start').val()
						+'&stopDate='+$('#tm-stop').val(),
				    page:	1
				}
			    )
			    .trigger('reloadGrid');
		    }
		);

		$('a#tm-setPeriod').click
		(
		    function()
		    {
			$('table#jqg-TimeReport')
			    .jqGrid
			    (
				'setGridParam',
				{
				    url:	'timeReport.php?manager_id='+$('select#manager-id').val()
						+'&startDate='+$('#tm-start').val()
						+'&stopDate='+$('#tm-stop').val(),
				    page:	1
				}
			    )
			    .trigger('reloadGrid');
		    }
		);
	    }
	);

    }
);
{/literal}-->
</script>

<!-- Окно тайм-менеджмента -->
<div class="dialog" id="time-management">
    <table width="100%" class="ui-widget">
	<tr>
	    <td align="right"><strong>Менеджер</strong></td>
	    <td>
		<select id="manager-id">
		    <option value="">&mdash;</option>
		{foreach from=$managers item=manager}
		    <option value="{$manager.id}">{$manager.manager_name}</option>
		{/foreach}
		</select>
	    </td>
	</tr>
	<tr>
	    <td align="right"><strong>Период:</strong></td>
	    <td>
		с <input type="text" id="tm-start" class="date" value="{$smarty.now|date_format:'%Y-%m-01'}"/>
		по <input type="text" id="tm-stop" class="date" value="{$smarty.now|date_format:'%Y-%m-%d'}"/>
		<a href="javascript:void(0)" id="tm-setPeriod"><img src="images/icons/tick_16.png"/></a>
	    </td>
	</tr>
    </table>
    <table id="jqg-TimeReport"></table>
    <div id="jqg-TimeReport-pager"></div>
</div>
